﻿#region Using Directives

using System;

#endregion

namespace GeekRule.ORM.Query
{
    /// <summary>
    /// Commonly used query patterns
    /// </summary>
    public class MsSqlQueryPatterns
    {
        private const string GetDatabaseVersion = "SELECT @@VERSION;";
        private const string GetParametersForRoutine = "SELECT SPA.* FROM sys.parameters SPA inner join sys.procedures SPO on SPA.object_id = SPO.object_id WHERE SCHEMA_NAME(SPO.schema_id) + '.' + OBJECT_NAME(SPO.object_id) = '{0}'";
        private const string SelectPattern = "SELECT {0} FROM {1} WHERE {2}";
        private const string SelectWithMaxRecordsPattern = "SELECT TOP {3} {0} FROM {1} WHERE {2}";

        public static string GetQueryPattern(QueryStatement pattern)
        {
            switch(pattern)
            {
                case QueryStatement.GetDatabaseVersion:
                    return GetDatabaseVersion;
                case QueryStatement.GetParametersForRoutine:
                    return GetParametersForRoutine;
                case QueryStatement.Select:
                    return SelectPattern;
                case QueryStatement.SelectWithMaxRecords:
                    return SelectWithMaxRecordsPattern;
            }

            throw new NotImplementedException("Query pattern not implemented: " + pattern);
        }
    }
}
